package org.yang.parser.types;

import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import org.yang.parser.State;

public class ClassType extends Type {

    public String name;
    public Type superClass;
    private InstanceType instance;

    public ClassType(@NotNull String name, @Nullable State parent){
        this.name = name;
        this.setTable(new State(parent, State.StateType.CLASS));
        table.setType(this);
        if(parent != null){
            table.setPath(parent.extendPath(name));
        } else {
            table.setPath(name);
        }
    }

    public ClassType(@NotNull String name, State parent, @Nullable Type superClasss){
        this(name, parent);
        if(superClass != null){
            addSuper(superClass);
        }
    }

    public void addSuper(@NotNull Type superClass){
        this.superClass = superClass;
        table.addSuper(superClass.table);
    }

    @Override
    public boolean typeEquals(Object others) {
        return false;
    }

    public InstanceType getInstance(){
        if(instance == null){
            instance = new InstanceType(this);
        }
        return instance;
    }


}
